home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
dev
/
misc
/
egs.lha
/
EGS
/
EGS_Devels
/
Examples
/
Other
/
Eyes.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-17
|
6KB
|
297 lines
/**
** Author: D.H. / U.S.
** Last Change : 14. Juli 1992 mvk
** SAS adaption
** 17 Dec 1992 mvk
**
** Description:
** Eyes looking at the mouse pointer
**
** (C) by VIONA Development 1991,1992,1993
**
**/
#include <stdio.h>
#include <stdlib.h>
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <egs/egs.h>
#include <egs/egsintuigfx.h>
#include <egs/egsintui.h>
#include <egs/egslayers.h>
#include <egs/egsgfx.h>
#include <egs/proto/egs.h>
#include <egs/proto/egslayers.h>
#include <egs/proto/egsgfx.h>
#include <egs/proto/egsintui.h>
struct EI_NewWindow newWindow =
{
200, 0, 300, 150,
300, 150, 300, 150,
NULL,
EI_WINDOWCLOSE+EI_WINDOWBACK+EI_WINDOWDRAG,
NULL, /* GadgetPtr */
"Eyes",
EI_SIMPLE_REFRESH,
EI_iCLOSEWINDOW+EI_iREFRESHWINDOW
/* ... anyway */
};
EI_WindowPtr win;
EG_RastPortPtr rast;
E_EBitMapPtr ras;
struct EG_AreaInfo info;
EG_Polygon buffer[40];
WORD midX, midY;
WORD radius;
WORD prad;
WORD rmax, xmax, ymax;
struct Library *EGSIntuiBase,*EGSGfxBase,*EGSLayersBase,*EGSBase;
void DrawEyes (void)
{
rast->APen = win->WinColors.Dark;
EG_AreaCircle(rast, (WORD)(midX-radius), (WORD)(midY),(WORD)(radius-4));
EG_AreaCircle (rast,(WORD)(midX+radius), (WORD)(midY), (WORD)(radius-4));
rast->APen = win->WinColors.Light;
EG_AreaCircle(rast, (WORD)(midX-radius), (WORD)(midY),(WORD)(radius-6));
EG_AreaCircle (rast,(WORD)(midX+radius), (WORD)(midY), (WORD)(radius-6));
}
void DrawPupill (WORD x, WORD y)
{
rast->APen = win->WinColors.Dark;
EG_AreaCircle (rast, (WORD)x, (WORD)y, (WORD)prad);
rast->APen = win->WinColors.Light;
EG_AreaCircle (rast, (WORD)(x-prad / 2), (WORD)(y-prad / 2), (WORD)(prad / 4));
}
void RedrawPupill (WORD x, WORD y)
{
rast->APen = win->WinColors.Light;
EG_AreaCircle (rast, (WORD)x, (WORD)y, (WORD)prad);
}
WORD py1, py2, px1, px2;
WORD oy1, oy2, ox1, ox2;
WORD oldX, oldY;
WORD SQR (LONG x)
{
WORD h1, h2, h3;
if ((x<0) || (x>2000*2000))
x = 1;
h1 = 1;
h2 = x / 2;
while ((h1*h1>x) || (h1+1)*(h1+1)<x)
{
h3 = (h1+h2) / 2;
h2 = h1;
h1 = x / h3; /* oder h3 / x ??? */
}
return h1;
}
void CalcPupills (WORD dx, WORD dy)
{
py1 = midY + ( (dy*(radius-prad-6)) / rmax);
px1 = midX + ( ((dx+radius)*(radius-prad-6)) / rmax) - radius;
py2 = midY + ( (dy*(radius-prad-6)) / rmax);
px2 = midX + ( ((dx-radius)*(radius-prad-6)) / rmax) + radius;
}
void RedrawPupills (void)
{
if ((oldX!=win->WScreen->EScreen->MouseX) ||
(oldY!=win->WScreen->EScreen->MouseY))
{
oldX = win->WScreen->EScreen->MouseX;
oldY = win->WScreen->EScreen->MouseY;
CalcPupills ((WORD)(oldX-(win->LeftEdge+midX)),(WORD)(oldY-(win->TopEdge+midY)));
EL_LockLayer (win->WLayer);
E_MouseOff (win->WScreen->EScreen);
RedrawPupill (ox1, oy1);
DrawPupill (px1, py1);
ox1 = px1;
oy1 = py1;
RedrawPupill (ox2, oy2);
DrawPupill (px2, py2);
ox2 = px2;
oy2 = py2;
E_MouseOn (win->WScreen->EScreen);
EL_UnlockLayer (win->WLayer);
}
}
void ReDraw (void)
{
DrawEyes ();
DrawPupill (px1, py1); ox1 = px1; oy1 = py1;
DrawPupill (px2, py2); ox2 = px2; oy2 = py2;
}
void Crash (char *string)
{
if (win!=NULL)
{
EI_CloseWindow (win);
win = NULL;
}
if (ras!=NULL)
E_DisposeBitMap (ras);
if (EGSIntuiBase)
CloseLibrary (EGSIntuiBase);
if (EGSGfxBase)
CloseLibrary (EGSGfxBase);
if (EGSLayersBase)
CloseLibrary (EGSLayersBase);
if (EGSBase)
CloseLibrary (EGSBase);
if (string != NULL)
{
printf ("%s\n", string);
exit (20L);
}
exit (0L);
}
EI_EIntuiMsgPtr msg;
BOOL done;
extern float sqrt (float f);
void main (void)
{
/* Öffne die Bibliotheken */
EGSBase = (APTR) OpenLibrary ("egs.library", 0);
if (NULL == EGSBase)
Crash ("Can't open EGS.library ");
EGSIntuiBase = (APTR) OpenLibrary ("egsintui.library", 0);
if (NULL == EGSIntuiBase)
Crash ("Can't open EGSIntui.library ");
EGSGfxBase = (APTR) OpenLibrary ("egsgfx.library", 0);
if (NULL == EGSGfxBase)
Crash ("Can't open EGSGfx.library ");
EGSLayersBase = (APTR) OpenLibrary ("egslayers.library", 0);
if (NULL == EGSLayersBase)
Crash ("Can't open EGSLayers.library ");
win = NULL;
win = EI_OpenWindow (&newWindow);
if (win == NULL)
Crash ("Can't open window !");
rast = win->RPort;
midX = win->BorderLeft + win->Width / 2;
midY = win->BorderTop + win->Height / 2;
radius = win->Height / 2;
prad = (radius*2) / 5;
rmax = (WORD) (sqrt( (float) (( (win->WScreen->Width-radius)*
(win->WScreen->Width-radius)) +
((win->WScreen->Height-radius)*
(win->WScreen->Height-radius) )) ) );
ras = E_AllocBitMap (win->Width, win->Height, (UWORD)1, 0, 0,
win->WScreen->EScreen->Map);
if (ras == NULL)
Crash ("Can't get mem for EBitMap ");
else
{
rast->TmpRas = ras;
rast->AreaInfo = EG_InitArea (&info, &buffer[0], (WORD)500);
oldX = win->WScreen->EScreen->MouseX;
oldY = win->WScreen->EScreen->MouseY;
CalcPupills ((WORD)(oldX-(win->LeftEdge+midX)),(WORD)(oldY-(win->TopEdge+midY)));
ReDraw ();
done = FALSE;
do {
Delay (10);
msg = (EI_EIntuiMsgPtr)GetMsg (win->UserPort);
while (msg!=NULL)
{
if (EI_iREFRESHWINDOW & msg->Class)
{
if (EI_BeginRefresh (win, (LONG)msg->IAddress))
{
ReDraw ();
EI_EndRefresh (win, TRUE);
}
}
if (EI_iCLOSEWINDOW & msg->Class)
done = TRUE;
ReplyMsg ((struct Message *)msg);
msg = (EI_EIntuiMsgPtr) GetMsg (win->UserPort);
}
RedrawPupills ();
} while (! done);
}
/* THE END */
Crash (NULL);
}